// import weaCube from 'weaCube';
// const ExcelLayoutCom = weaCube.common.ExcelLayoutCom;
// const ReplyCom = weaCube.common.ReplyCom;
// const SingleShareDialog = weaCube.common.SingleShareDialog;
import { inject, observer } from 'mobx-react';
import { Spin,message } from 'antd';
import {WeaRightMenu} from 'ecCom';
import { toJS } from "mobx";

@inject('contractPageStore','synergyStore')
@observer
class ContractPage extends React.Component {
    constructor(props) {
        super(props);
        window._cubeCard={
            reLoad:this.showCardCallBack,
            editCard:this.editCard,
            delCard:this.delCard
        }
    }
    showCardCallBack = (billId)=>{
        //编辑保存后，返回查看页面
        message.success('保存成功');
        if(billId){
            let {contractPageStore} = this.props;
            contractPageStore.getLayoutInfo(billId);
        }
    }
    editCard=(params)=>{
        //点击编辑，加载编辑界面
        if(params){
            let {contractPageStore} = this.props;
            contractPageStore.setEditBill(params);
        }
        return null;
    }

    delCard=(d)=>{
        message.success('删除成功');
        let {synergyStore} = this.props;
        synergyStore.isUseSynergy(false);
        window._contractTable.reload();
    }

    componentWillMount(){
        const {initPageWidth} = this.props.contractPageStore;
        const pageWidth = this.props.pageWidth||1200;
        initPageWidth(pageWidth-35);
    }

    componentWillUnmount(){
        window._cubeCard={}
    }

    componentDidMount() {
        if(window.weaCube){
            this.doInit(this.props);
        }else{
            eventRegister.loadModule('f_cube', ()=> {
                this.doInit(this.props);
            })
        }
    }

    doInit(props){
        const billId = props.refId;
        const {getLayoutInfo} = props.contractPageStore;
        getLayoutInfo(billId);
    }

    componentWillReceiveProps(nextProps) {
        const _omponentWillReceiveProps = this.props.refId !== nextProps.refId;
        if (_omponentWillReceiveProps) {
            const refId = nextProps.refId;
            const { getLayoutInfo } = this.props.contractPageStore;
            getLayoutInfo(refId);
        }
    }

    render() {
        const billId = this.props.refId;
        const pageWidth = this.props.pageWidth;
        const {Card,modeInfo} = this.props.contractPageStore;
        // const rightMenus = Card.cardTab.rightMenus.slice();
        // rightMenus.map(c=>{
        //     if(c.function.indexOf('toEdit')>0){
        //         let paramstr = `type=2&billid=${billId}&modeId=${modeInfo.modeId}&formId=${modeInfo.formId}`;
        //         if(typeof(modeInfo.editLoyoutid)!=="undefined"){
        //             paramstr = `type=2&billid=${billId}&modeId=${modeInfo.modeId}&formId=${modeInfo.formId}&layoutid=${modeInfo.editLoyoutid}`;
        //         }
        //         c.function="window.openFullWindowHaveBar('#/main/cube/card?"+paramstr+"','"+billId+"')";
        //     }
        //     if(c.function.indexOf('toDel')>0){
        //         rightMenus.remove(c);
        //     }
        // })
// console.log(toJS(Card));  wea-contract-contractPage-detail
            // Card.modeExcel.containerWidth = pageWidth-30
        let ExcelLayoutCom = {};
        let ReplyCom = {};
        let SingleShareDialog = {};
        if(window.weaCube){
            ExcelLayoutCom = weaCube.common.ExcelLayoutCom;
            ReplyCom = weaCube.common.ReplyCom;
            SingleShareDialog = weaCube.common.SingleShareDialog;
        }

        return (
            <div className="wea-contract-contractPage">
                <div className="coms-mode-docker coms-mode-card wea-contract-contractPage-detail">
                    {window.weaCube&&<Spin spinning={Card.loading}>
                        {/* <WeaRightMenu datas={rightMenus} onClick={Card.cardTab.rightMenuHandle}> */}
                        {Card.isInit ? [<ExcelLayoutCom key={Card.base.type} Card={Card} />,
                        <SingleShareDialog
                            share={Card.share}
                            formId={Card.base.formId}
                            modeId={Card.base.modeId}
                            nonDefaultShared={Card.base.nondefaultshared}
                            defaultShared={Card.base.defaultshared}
                            type='0'
                        />
                        ]
                        :
                         <div style={{marginTop:'50%'}}  />}
                        {/* </WeaRightMenu> */}
                    </Spin>}
                    {window.weaCube&&Card.reply && Card.base.showReply && Card.base.type == '0' && <ReplyCom reply={Card.reply} />}
                </div>
            </div>
        );
    };

    // openFullWindowHaveBar(url){
	// 	var redirectUrl = url;
	// 	var width = screen.availWidth - 10;
	// 	var height = screen.availHeight - 50;
	// 	var szFeatures = "top=0,";
	// 	szFeatures += "left=0,";
	// 	szFeatures += "width=" + width + ",";
	// 	szFeatures += "height=" + height + ",";
	// 	szFeatures += "directories=no,";
	// 	szFeatures += "status=yes,toolbar=no,location=no,";
	// 	szFeatures += "menubar=no,";
	// 	szFeatures += "scrollbars=yes,";
	// 	szFeatures += "resizable=yes"; //channelmode
	// 	window.open(redirectUrl, "", szFeatures);
	// }
}

export default ContractPage;